var welId = '';

$(function() {
	// 拖拽到新增标签
	$('#new_target').on("dragover", function(e) {
		e.preventDefault();
	});
	// 拖拽新增
	$('#new_target').on("drop", function(e) {
		e.stopPropagation();
	    e.preventDefault();
		drop();

	});
	// 删除快捷菜单
	$('.expressClose').on("click", function(e) {
		deleteWel(e);

	});
	// 快捷菜单打开页面
	$('.openMenu').on("click", function(e) {
		openTab(e, $(this));

	});
	// 拖拽-拖 事件
	$('.menu_li').on("dragover", function(e) {
		e.preventDefault();
	});
	var sourceWelId = '';
	var sourceSort = '';
	// 拖拽开始
	$('.menu_li').on("dragstart", function(e) {
		sourceWelId = $(this).attr("welId");
		sourceSort = $(this).attr('welIndex');
	});
	// 拖拽-鼠标放
	$('.menu_li').on("drop",function(e) {
		if (sourceWelId == null || sourceWelId == ''|| sourceWelId == undefined) {
			return;
		}
		var welId = $(this).attr("welId");
		var sort = $(this).attr('welIndex');
		var obj = {
			sourceWelId : sourceWelId,
			targetWelId : welId,
			sourceSort : sort,
			targetSort : sourceSort
		};
		$.post(ctx + "admin/welcome/changePoint", {
			params : JSON.stringify(obj)
		}, function(data) {
			if (data.data)
				$.modal.reload();
			else
				$.modal.alertError(data.msg);
		});
		welId = '';
	});
	
	
	//ie8 
	var userAgent = navigator.userAgent;
	var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; 
	if(isIE) {
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        if(fIEVersion == 8) {
        	$('.index_bg .mainmenu li:nth-child(8n+1)').css('backgroundColor','#36A1DB')
        	$('.index_bg .mainmenu li:nth-child(8n+2)').css('backgroundColor','#678ce1')
        	$('.index_bg .mainmenu li:nth-child(8n+3)').css('backgroundColor','#8c67df')
        	$('.index_bg .mainmenu li:nth-child(8n+4)').css('backgroundColor','#84d018')
        	$('.index_bg .mainmenu li:nth-child(8n+5)').css('backgroundColor','#14c760')
        	$('.index_bg .mainmenu li:nth-child(8n+6)').css('backgroundColor','#f3b613')
        	$('.index_bg .mainmenu li:nth-child(8n+7)').css('backgroundColor','#ff8a4a')
        	$('.index_bg .mainmenu li:nth-child(8n+8)').css('backgroundColor','#fc5366')
        } 
    }
});
function openTab(e, that) {
	var url = that.attr('path');
	var label = that.attr('label');
	$.modal.openTab(label, url);
}
function drop() {
	var st = window.sessionStorage.getItem("targetMenu");
	if (st == null || st == undefined || st == '') {
		return;
	}
	var obj = JSON.parse(st);
	$.post(ctx + "admin/welcome", obj, function(data) {
		if (data.data){
//			$.modal.reload();
			window.location.reload();
			
		}else{
			$.modal.alertError(data.msg);
		}
			
	});
	window.sessionStorage.removeItem("targetMenu");
}
function deleteWel(e) {
	var welId = e.target.id;
	$.operate.post(ctx + "admin/welcome/" + welId, {}, function(data) {
		if (data.data){
//			$.modal.reload();
//			$('#'+welId).parents('.menu_li').remove()
			window.location.reload();
		}else{
			$.modal.alertError(data.msg);	
		}
			
	});
}